<template>
  <div class="td-layer">
    <el-dialog
      :title="title"
      :visible.sync="visibleLayer"
      :width="width"
      :top="top"
      :modal-append-to-body="modalAppendToBody"
      :appendToBody="appendToBody"
      :before-close="beforeClose"
      :close-on-click-modal="closeOnClickModal"
    >
      <div class="title" slot="title">{{ title }}</div>
      <slot></slot>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'TdLayer',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '弹出层标题'
    },
    width: {
      type: String,
      default: '50%'
    },
    top: {
      type: String,
      default: '15vh'
    },
    modalAppendToBody: {
      type: Boolean,
      default: true
    },
    appendToBody: {
      type: Boolean,
      default: false
    },
    closeOnClickModal: {
      type: Boolean,
      default: false
    },
    beforeClose: {
      type: Function,
      default: done => {
        done()
      }
    }
  },
  data() {
    return {
      visibleLayer: false
    }
  },

  watch: {
    visible(v) {
      this.visibleLayer = v
    },
    visibleLayer(v) {
      if (!v) {
        this.$emit('update:visible', v)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.td-layer {
  & /deep/ .el-dialog {
    .el-dialog__body {
      max-height: 80vh;
      overflow-y: auto;

      &::-webkit-scrollbar {
        width: 6px;
      }
      &::-webkit-scrollbar-thumb {
        width: 6px;
        border-radius: 6px;
        background: rgba($color: #000000, $alpha: 0.5);
      }
    }
  }
}
.title {
  font-size: 16px;
  font-weight: bold;
  text-align: center;
}
</style>
